package com.wish.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.springframework.stereotype.Service;

import com.wish.model.Group;

@Service
public class GroupDao
{
	@PersistenceContext
	private EntityManager em;

	public void insert(Group group) throws RuntimeException
	{
		em.persist(group);
	}

	public void delete(long id) throws RuntimeException
	{
		em.remove(em.find(Group.class, id));
	}

	@SuppressWarnings("unchecked")
	public List<Group> getList()
	{
		String sql = "select g from Group g";
		Query query = em.createQuery(sql);
		return query.getResultList();
	}
}
